package com.item.yxlottery.yxlottery.utils;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

/**
 * Created by leo on 2017/1/6.
 */

public class Utils {

    private static String TAG = "XYLOTTERY";

    public static void log(String str)
    {
        Log.v(Utils.TAG, str);
    }

    public static void toast(Context context, String text)
    {
        if(TextUtils.isEmpty(text) || text.equals("null"))
            return;
        Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
    }


    public static void toast(Context context, int strId)
    {
        Toast.makeText(context, strId, Toast.LENGTH_SHORT).show();
    }

    public static void toastShowInCenter(Context context, String text)
    {
        if(TextUtils.isEmpty(text) || text.equals("null"))
            return;
        Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }


    /**
     *
     * setWindowStatusBarColor:设置状态栏颜色. <br/>
     *
     * @author jackie
     * @param activity
     * @param colorResId
     * @since JDK 1.6
     */
    public static void setWindowStatusBarColor(Activity activity, int colorResId) {
        try {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                Window window = activity.getWindow();
                //window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                //window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                window.setStatusBarColor(activity.getResources().getColor(colorResId));
                // 底部导航栏
                // window.setNavigationBarColor(activity.getResources().getColor(colorResId));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     *
     * setWindowTranslucent:设置透明状态栏. <br/>
     *
     */
    public static void setWindowTranslucent(Activity activity) {
        try {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                Window window = activity.getWindow();
                window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                window.setStatusBarColor(Color.TRANSPARENT);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
